// index.js
import Vue from 'vue'
import Router from 'vue-router'

import Login from '../components/Login.vue'
import Home from '../components/Home.vue'

import Student from '../components/student/Student.vue'
import StudentInfo from '../components/student/StudentInfo.vue'
import StudentList from '../components/student/StudentList.vue'
Vue.use(Router)

const router = new Router({
    routes: [
        {
            path: '/',
            redirect: '/login',
            component: Home,
            name: "home",
            hiden: false
        },
        {
            path: '/login',
            component: Login,
            name: "Login",
            hiden: false
        }
        ,
        {
            path: '/home',
            component: Home,
            name: "Home",
            hiden: true,

            children: [
                {
                    path: 'student',  // 改为相对路径，会渲染在Home组件的router-view中
                    component: Student,
                    meta: {
                        title: '学生管理',
                        icon: 'fa fa-users',
                        hidden: false
                    },
                    children: [
                        {
                            path: 'info',  // 相对路径
                            component: StudentInfo,
                            meta: {
                                title: '学生信息',
                                icon: 'fa fa-user',
                                hidden: false
                            }
                        },
                        {
                            path: 'list',  // 相对路径
                            component: StudentList,
                            meta: {
                                title: '学生列表',
                                icon: 'fa fa-list',
                                hidden: false
                            }
                        }
                    ]
                }
            ]

        }

    ],
    mode: 'history'



})
// 添加路由守卫
router.beforeEach((to, from, next) => {
    console.log("[路由跳转] 从:", from.path, "到:", to.path); // 必须打印
    next();
});


export default router;